import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'
// import enLang from 'element-ui/lib/locale/lang/en'// 如果使用中文语言包请默认支持，无需额外引入，请删除该依赖

// import 'font-awesome/css/font-awesome.min.css'
// 国际化
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log

import * as filters from './filters' // global filters

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
// 引入 vue-ele-form
import EleForm from 'vue-ele-form'

import EleFormImageUploader from 'vue-ele-form-image-uploader'

import EleFormTreeSelect from 'vue-ele-form-tree-select'

import { firstEle } from '@/utils/index'

import { mappingArray, mappingTreeArray } from '@/utils/tools'
import VXETablePluginElement from 'vxe-table-plugin-element'
import 'vxe-table-plugin-element/dist/style.css'
import { getToken } from '@/utils/auth'
import { config } from '@/utils/config'
// import EleFormQuillEditor from 'vue-ele-form-quill-editor'
import { quillEditor } from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

import Treeselect from '@riophae/vue-treeselect'
// import the styles
import '@riophae/vue-treeselect/dist/vue-treeselect.css'

import Vue2OrgTree from 'vue-tree-color'
import draggable from 'vuedraggable'
Vue.component('draggable', draggable)

// https://www.cnblogs.com/10ve/p/12573772.html
Vue.use(Vue2OrgTree)

// 注册 tree-select 组件
Vue.component('tree-select', EleFormTreeSelect)

import Vant from 'vant'
import 'vant/lib/index.css'

Vue.use(Vant)

Vue.use(VXETable)
VXETable.use(VXETablePluginElement)
Vue.use(Element, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  locale: locale // 如果使用中文，无需设置，请删除
})

import animated from 'animate.css'
import objectEach from "xe-utils/methods";

Vue.use(animated)

// 注册 ele-form
Vue.use(EleForm, {
  'tree-select': {
    clearable: true // 所有的 tree-select 都会有 clearable = true的属性值
  }
  // // 可以为编辑器配置全局属性, 每个实例都共享这个属性
  // 'quill-editor': {
  //   // 比如设置上传 action 后, 所有的 quill-editor 编辑器上传图片都会采用这个属性
  //   action: config.uploadUrl
  // }
})

// 注册 image-uploader 组件
Vue.component('image-uploader', EleFormImageUploader)
// 注册 quill-editor 组件
Vue.component('quill-editor', quillEditor)
Vue.component('treeselect', Treeselect)

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

Vue.prototype.firstEle = firstEle
Vue.prototype.mappingArray = mappingArray
Vue.prototype.mappingTreeArray = mappingTreeArray
Vue.prototype.getToken = getToken
Vue.prototype.uploadUrl = config.uploadUrl
Vue.prototype.addProperty = function(object, key, value, unit) {
  if (object) {
    if (value) {
      if (unit) {
        object[key] = value + unit
      } else {
        object[key] = value
      }
    }
  }
}

Vue.directive('has', { inserted: function(el, binding, vnode) {
  // 菜单按钮权限
  const btnPermissions = vnode.context.$route.meta.btnPerms
  console.log(btnPermissions)
  const perm = binding.value
  if (btnPermissions && perm) {
    const exist = btnPermissions.some(el => el === perm)
    if (!exist) {
      el.parentNode.removeChild(el)
    }
  }
} })

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
